
package ManagerInfoFile;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileNodeMap {
    private String fileName;
    private NodeInfo[] danhSachNode;
    public FileNodeMap()
    {
        this.fileName = "./Map/Nodes.map";
        danhSachNode = null;
    }
    public String GetFileName()
    {
        return this.fileName;
    }
    public void ReadNodeMap(String filename)
    {
        FileReader fileReader = null;
        int nNode = 0;
        int i = 0;
        try {
            fileReader = new FileReader(filename);
            BufferedReader br = new BufferedReader(fileReader);
            String line;
            line = br.readLine();
            if(line != null)
            {
                nNode = Integer.parseInt(line);
                danhSachNode = new NodeInfo[nNode];
                
            }
            while((line = br.readLine()) !=  null)
            {
                String [] strTemp = line.split(" ");
                NodeInfo node = new NodeInfo(strTemp[1].toString(),
                        Integer.parseInt(strTemp[2].toString()),
                        Integer.parseInt(strTemp[3].toString()));
                danhSachNode[i] = node;
                i++;
                    
            }
            fileReader.close();
        } catch (FileNotFoundException ex) {
            System.out.println("Lỗi, Không tìm Thấy File Node "+ex.getMessage());
        } catch(IOException io){
            System.out.println("Lỗi, Đọc Dữ Liệu File Node "+io.getMessage());
        }
    }
    public NodeInfo GetNodeInfo(int index)
    {
       if(index >= 0 && index < this.danhSachNode.length)
           return danhSachNode[index];
       return null;
    }
    public int GetLength()
    {
        return this.danhSachNode.length;
    }
}
